package com.sakura.config;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 *
 *
 * @author : Sakura
 * @Date : 2023/9/1 9:34
 * @Description : 时间字段自动刷新
 */
@Component
public class CommonMetaObjectHandler implements MetaObjectHandler {
//    字段插入自动填充
//    @TableField(fill = FieldFill.INSERT)
//    private Date createTime;
//    字段更新自动填充
//    @TableField(fill = FieldFill.INSERT_UPDATE)
//    private Date updateTime;

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
        this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
    }
}
